import java.util.Stack;
public class Main {
    public static void main(String[] args) {
//        System.out.println("Hello world!");

    }
}
class MyQueue {
    //使用队列实现栈
    private final Stack<Integer> s1;
    private final Stack<Integer> s2;

    public MyQueue() {
        s1 = new Stack<Integer>();
        s2 = new Stack<Integer>();
    }

    public void push(int x) {
        s1.add(x);
    }

    public int pop() {
        if(s2.empty()) {
            while(!s1.empty()) {
                int x = s1.pop();
                s2.push(x);
            }
        }
        return s2.pop();
    }

    public int peek() {
        if(s2.empty()) {
            while(!s1.empty()) {
                int x = s1.pop();
                s2.push(x);
            }
        }
        return s2.peek();
    }

    public boolean empty() {
        //若是两个栈均为空，则队列为空
        return s1.empty() && s2.empty();
    }
}